package org.ldh.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class MultiDataSourceService {

    private final JdbcTemplate postgresqlJdbcTemplate;
    private final JdbcTemplate mysqlJdbcTemplate;
    /*private final JdbcTemplate oracleJdbcTemplate;*/

    @Autowired
    public MultiDataSourceService(
            @Qualifier("postgresqlJdbcTemplate") JdbcTemplate postgresqlJdbcTemplate,
            @Qualifier("mysqlJdbcTemplate") JdbcTemplate mysqlJdbcTemplate/*,
            @Qualifier("oracleJdbcTemplate") JdbcTemplate oracleJdbcTemplate*/) {
        this.postgresqlJdbcTemplate = postgresqlJdbcTemplate;
        this.mysqlJdbcTemplate = mysqlJdbcTemplate;
        /*this.oracleJdbcTemplate = oracleJdbcTemplate;*/
    }

    public void queryFromPostgreSQL() {
        System.out.println("psql---------------");
        String sql = "SELECT * FROM lava_job_info limit 2";
        postgresqlJdbcTemplate.query(sql, (rs, rowNum) -> {
            // 处理结果集
            System.out.println("job_id---" + rs.getInt("job_id"));
            return rs;
        });
    }

    public void queryFromMySQL() {
        String sql = "SELECT * FROM student";
        System.out.println("mysql---------------");
        mysqlJdbcTemplate.query(sql, (rs, rowNum) -> {
            // 处理结果集
            System.out.println("id---" + rs.getInt("id"));
            return rs;
        });
    }

    /*public void queryFromOracle() {
        String sql = "SELECT * FROM oracle_table";
        oracleJdbcTemplate.query(sql, (rs, rowNum) -> {
            // 处理结果集
            return null;
        });
    }
*/
    // 其他数据库操作方法...
}
